﻿using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using UWP.Douban.Views;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace UWP.Douban.Mvvm
{
    public abstract class BaseVm : INotifyPropertyChanged
    {
        protected Windows.UI.Xaml.Controls.Page Page;
        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged([CallerMemberName]string propertyName="")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(""));
        }

        public Frame ScenarioFrame
        {
            get
            {
                return MainPage.Current.ThisScenarioFrame;
            }
        }

        public void Navigate(Type pageType,object parameter)
        {
            ScenarioFrame.Navigate(pageType, parameter);
        }

        protected void GoBack()
        {
            //调用主界面Frame进行后退
            if (ScenarioFrame.CanGoBack)
            {
                ScenarioFrame.GoBack();
            }
        }

        public void OnNavigatedTo(NavigationEventArgs e, BasePage page)
        {
            Page = page;
            OnNavigatedTo(e);
        }

        public virtual void OnNavigatedTo(NavigationEventArgs e)
        {

        }

        public virtual void OnNavigatedForm(NavigationEventArgs e)
        {
        }
    }
}